package com.wang.web3.adapter;

import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.wang.web3.R;
import com.wang.web3.bean.GirlBean;
import com.wang.web3.bean.PropsBean;
import com.wang.web3.utils.CalendarUtils;

import java.util.List;

/**
 * @author Mr.Wang
 * @version v0.3.2
 * @time 2017/7/12
 * @describe
 */

public class PropsAdapter extends BaseQuickAdapter<PropsBean.DataBean, BaseViewHolder> {

    LinearLayout rootView;
    PersonHolderListener personHolderListener;
    ImageView iv_img;


    public PropsAdapter(List<PropsBean.DataBean> mGirlBean, PersonHolderListener personHolderListener) {
        super(R.layout.props_item_layout, mGirlBean);
        this.personHolderListener = personHolderListener;
    }


    @Override
    protected void convert(final BaseViewHolder helper, PropsBean.DataBean item) {

        rootView = helper.getView(R.id.rootView);
        iv_img = helper.getView(R.id.iv_img);
        Glide.with(mContext).load(item.getItemPic()).into(iv_img);

        helper.setText(R.id.tvName,item.getCategoryName());
        helper.setText(R.id.tvTime, CalendarUtils.getScTime(item.getItemDuration()));
        helper.setText(R.id.tvLv,item.getRarity());


        rootView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    personHolderListener.onPersonItemClicked(v, event, helper.getAdapterPosition());
                }
                return false;
            }
        });
    }


    public interface PersonHolderListener<T> {

//        void onPersonItemClicked(View v, MotionEvent event, int position);

        void onPersonItemClicked(View v, MotionEvent event, int position);
    }

}
